package edu.ucsd.db.bassarisk.algebra.logical;

import java.util.List;

import edu.ucsd.db.bassarisk.algebra.logical.visitor.LogicalOperatorVisitor;
import edu.ucsd.db.bassarisk.query.binding.Bindings.MapFunctionValueBinding;

public class Map extends LogicalOperator {
  private final List<MapFunctionValueBinding> mappedFunctions;
  private final LogicalOperator subPlan;

  public Map(List<MapFunctionValueBinding> mappedFunctions, LogicalOperator subPlan) {
    this.mappedFunctions = mappedFunctions;
    this.subPlan = subPlan;
  }

  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Map [");
    for (MapFunctionValueBinding binding : this.mappedFunctions) {
      sb.append(" ").append(binding.toString()).append(",");
    }
    sb.append("] {\n").append(subPlan.toString()).append("}");
    return sb.toString();
  }

  @Override
  public <R, A> R accept(LogicalOperatorVisitor<R, A> visitor, A arg) {
    return visitor.visitMap(this, arg);
  }

  public List<MapFunctionValueBinding> functions() {
    return mappedFunctions;
  }

  public LogicalOperator subPlan() {
    return subPlan;
  }
}
